package com.datastructure.test.findfirstnorepeatedcharinstream;

import java.util.ArrayList;
import java.util.HashSet;

public class FindFirstNoRepeatedCharInStream {

    public static void main(String[] args) {
        FindFirstNoRepeatedCharInStream findFirstNoRepeatedCharInStream = new FindFirstNoRepeatedCharInStream();
        StringBuilder caseout = new StringBuilder();
        String original = "googgle";
        char[] charArray = original.toCharArray();
        for (char c : charArray) {
            findFirstNoRepeatedCharInStream.Insert(c);
            caseout.append(findFirstNoRepeatedCharInStream.FirstAppearingOnce());
        }
        System.out.println(caseout.toString());
    }

    public ArrayList<Character> store = new ArrayList<>();
    public ArrayList<Character> temp = new ArrayList<>();
    //Insert one char from stringstream
    public void Insert(char ch) {
        if(!store.contains(ch)&&!temp.contains(ch)){
            store.add(ch);
        }else {
            store.remove((Character) ch);
            temp.add(ch);
        }
    }
    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce(){
        if(store.size()==0){
            return '#';
        } else {
            return store.get(0);
        }
    }

}
